package com.kaifamiao.month05.day06;


public class MyThread extends Thread {

    private static int tickets = 100;

    public MyThread() {
        super();
    }

    public MyThread(String name) {
        super(name);
    }

    @Override
    public void run() {
        while (tickets > 0) {
            synchronized (MyThread.class) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(this.getName() + "正在买第 " + tickets-- + "张票！");
            }
        }
    }
}
